home *** CD-ROM | disk | FTP | other *** search
/ Software Explosion / Software Explosion (Fore-Matt Home Computing)(1996).iso / games / workbench / labyrinth_ii / readfile.c < prev    next >
C/C++ Source or Header  |  1988-10-04  |  1KB  |  64 lines

  1.  
  2. /* Readfile scans a file from disk and prints it out using the formatted
  3.  * print routine in console.c. Written 1987 by Russell Wallace. */
  4.  
  5. #include <libraries/dos.h>
  6.  
  7. #define BUFLEN 256L
  8. #define EOF '\0'
  9.  
  10. char inbuffer[BUFLEN];
  11. char prbuf[BUFLEN];
  12.  
  13. char charin (fp)
  14. struct FileInfoBlock *fp;
  15. {
  16.     static LONG inpoint=BUFLEN-1;
  17.     static LONG maxin=BUFLEN-1;
  18.     LONG Read ();
  19.     char ch;
  20.     if (++inpoint>=maxin)
  21.     {
  22.         maxin=Read (fp,inbuffer,BUFLEN);
  23.         inpoint=0;
  24.     }
  25.     if (maxin==0)
  26.         return (0);    /* End of file */
  27.     ch=inbuffer[inpoint];
  28.     if (ch<' ' && ch!='\0' && ch!='\n')
  29.         ch=' ';        /* Don't give any weird characters like some WPs put in */
  30.     return (ch);
  31. }
  32.  
  33. short readfile (filename)
  34. char *filename;
  35. {
  36.     struct FileInfoBlock *fp,*Open ();
  37.     char charin ();
  38.     int endoffile=0;
  39.     short i;
  40.     if (!(fp=Open (filename,MODE_OLDFILE)))
  41.         return (1);    /* Error */
  42.     do
  43.     {
  44.         i=0;
  45.         do
  46.             prbuf[i++]=charin (fp);
  47.         while (prbuf[i-1]!=EOF && i<200);
  48.     if (prbuf[i-1]!=EOF)
  49.         {
  50.         do
  51.             prbuf[i++]=charin (fp);
  52.         while (prbuf[i-1]!=EOF && i<250 && prbuf[i-1]!=' ');
  53.         }
  54.     if (prbuf[i-1]!=EOF)
  55.         prbuf[i]='\0';
  56.             else
  57.                 endoffile++;
  58.         print (prbuf);
  59.     }
  60.     while (endoffile==0);
  61.     Close (fp);
  62.     return (0);
  63. }
  64.